package com.wmlive.hhvideo.heihei.mainhome.presenter;

import android.text.TextUtils;

import com.wmlive.hhvideo.common.network.HttpConstant;
import com.wmlive.hhvideo.heihei.beans.main.UpdateInfo;
import com.wmlive.hhvideo.heihei.beans.splash.InitCatchData;
import com.wmlive.hhvideo.heihei.splash.presenter.SplashPresenter;
import com.wmlive.hhvideo.heihei.splash.view.SplashView;
import com.wmlive.networklib.entity.DCNetObserver;


/**
 * Created by lsq on 7/5/2017.
 * 首页的presenter
 */

public class MainNewPresenter extends SplashPresenter<MainNewPresenter.IMainNewView> {


    public MainNewPresenter(MainNewPresenter.IMainNewView view) {
        super(view);
    }

    //检查升级
    public void checkSystemAppUpdate(String version, String channel) {
        String url = InitCatchData.sysUpdateCheck();
        if (!TextUtils.isEmpty(url)) {
            executeRequest(HttpConstant.TYPE_CHECK_SYSTEM_UPLOAD_CODE,
                    getHttpApi().checkSystemAppUpdate(InitCatchData.sysUpdateCheck(), version, "android", "app_name", channel))
                    .subscribe(new DCNetObserver<UpdateInfo>() {
                        @Override
                        public void onRequestDataReady(int requestCode, String message, UpdateInfo response) {
                            if (viewCallback != null) {
                                viewCallback.checkSystemAppUpdateSucceed(response);
                            }
                        }

                        @Override
                        public void onRequestDataError(int requestCode, int serverCode, String message) {
                            if (viewCallback != null) {
                                viewCallback.checkSystemAppUpdateFailure(message);
                            }
                        }
                    });
        } else {
            onRequestUrlError(HttpConstant.TYPE_CHECK_SYSTEM_UPLOAD_CODE);
        }
    }


    public interface IMainNewView extends SplashView {
        void checkSystemAppUpdateSucceed(UpdateInfo updateInfo);

        void checkSystemAppUpdateFailure(String updateInfo);

    }
}
